using System.Text;
using System;
using System.Collections.Generic;
using System.Linq;

namespace DesignPattern.Structural.Composite
{
    public class Branch : Component
    {
        private List<Component> _children = new List<Component>();

        public Branch(string name) : base(name) {}

        public override void Display(int level)
        {
            string name = _name;

            for (var i = 0; i < level; i++)
            {
                name = "-" + name;
            }

            System.Console.WriteLine(name);

            foreach (var child in _children)
            {
                child.Display(level + 2);
            }
        }

        public void Add(Component component)
        {
            _children.Add(component);
        }

        public void Remove(Component component)
        {
            _children = _children.Where(c => !c.Equals(component)).ToList();
        }
    }
}